<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>修改管理员</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
        <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/index.js"></script>
         <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->

    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                   <form class="layui-form">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>我的登录名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" disabled="true" name="username" required="" lay-verify="required"
                          autocomplete="off" class="layui-input ">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为您唯一的登入名
                      </div>
                  </div>
                  
                
                    
                      
                      <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                       <span class="x-red">*</span>绑定菜单
                    </label>
                    <div id="aaa" class="layui-input-inline">
                        <select  id="role"  
                        autocomplete="off" class="layui-input">
                        <option value="78">管理员</option>
                        	<option value="79">超级管理员</option>
                        	<option value="1">员工</option>
	                        
	
                     </select>
                    </div>
                </div>
                
                
                 
                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="pass" required="" lay-verify="pass"
                          autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          6到16个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                          autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <input type="button" value="修改" id="add" class="layui-btn" >
                  </div>
              </form>
            </div>
        </div>
        <script>
     
		
        	layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    nikename: function(value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

             

            });



		
		 $("#username").val(localStorage.getItem("account"));
		  $("#L_pass").val(localStorage.getItem("pawd"));
		  
		  $("#role").each(function(index,val){
		  		if($(this).text()==localStorage.getItem("role")){
		  			val.attr("selected",true);
		  		}
		  })
		  
		
		$("#add").click(function()
		{
		 
							if($("#L_pass").val().length<6 )
							{
								alert('密码小于6');
								return;
							}
							if( $("#L_pass").val().length>12)
							{
								alert('密码大于12');
								return;
							}
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            alert('两次密码不一致');
                            return;
                        };
                        
          
                
               $.ajax({
		    type: "post",//请求方式
		    url: "http://localhost:16111/user/update_Administrator",//上s层的路径
			dataType: "json",
		    xhrFields:{withCredentials: true},
		    data:{account: $("#username").val(),
			  pawd: $('#L_pass').val(),
			  role_name:$("#role").val()},//传值
		   success: function (data)
			{
				var user = eval('(' + JSON.stringify(data) + ')');
				if(user.data==1)
				{
						opener.location.reload();
				}else{
					layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(data),{icon:2,time:1000});
             })
				}
			}
		})   
               
              
             
		})
</script>
</body>

</html>
